package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.common.domain.ZhDeptInfo;
import com.ruoyi.common.service.IZhDeptInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ZhBanner;
import com.ruoyi.system.service.IZhBannerService;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.annotation.DataScope;

/**
 * 轮播图 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-04-30
 */
@Controller
@RequestMapping("/system/zhBanner")
public class ZhBannerController extends BaseController
{
    private String prefix = "system/zhBanner";
	
	@Autowired
	private IZhBannerService zhBannerService;

	@Autowired
	private IZhDeptInfoService zhDeptInfoService;

	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhBanner:view")
	@GetMapping()
	public String zhBanner(ZhBanner zhBanner,ModelMap mmap)
	{
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhBanner.getParams())));
		return prefix + "/zhBanner";
	}
	
	/**
	 * 查询轮播图列表
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhBanner:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ZhBanner zhBanner)
	{
		startPage();
        List<ZhBanner> list = zhBannerService.selectZhBannerList(zhBanner);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出轮播图列表
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhBanner:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZhBanner zhBanner)
    {
    	List<ZhBanner> list = zhBannerService.selectZhBannerList(zhBanner);
        ExcelUtil<ZhBanner> util = new ExcelUtil<ZhBanner>(ZhBanner.class);
        return util.exportExcel(list, "zhBanner");
    }
	
	/**
	 * 新增轮播图
	 */
	@RequiresPermissions("system:zhBanner:add")
	@DataScope(tableAlias = "l")
	@GetMapping("/add")
	public String add(ZhBanner zhBanner,ModelMap mmap)
	{
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhBanner.getParams())));
		return prefix + "/add";
	}
	
	/**
	 * 新增保存轮播图
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhBanner:add")
	@Log(title = "轮播图", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ZhBanner zhBanner)
	{		
		return toAjax(zhBannerService.insertZhBanner(zhBanner));
	}

	/**
	 * 修改轮播图
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhBanner:edit")
	@GetMapping("/edit/{id}")
	public String edit(ZhBanner zhBanner,@PathVariable("id") Integer id, ModelMap mmap)
	{
		ZhBanner banner = zhBannerService.selectZhBannerById(id);
		mmap.put("zhBanner", banner);
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhBanner.getParams())));
		return prefix + "/edit";
	}
	
	/**
	 * 修改保存轮播图
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhBanner:edit")
	@Log(title = "轮播图", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ZhBanner zhBanner)
	{		
		return toAjax(zhBannerService.updateZhBanner(zhBanner));
	}
	
	/**
	 * 删除轮播图
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhBanner:remove")
	@Log(title = "轮播图", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(ZhBanner zhBanner,String ids)
	{		
		return toAjax(zhBannerService.deleteZhBannerByIds(ids));
	}
	
}
